package sever;

import constant.Constant;

import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class Sever {
    // 创建一个集合，用于保存所有客户端对象
    public static final Map<Socket, String> onLineSockets = new HashMap<>();
    public static void main(String[] args) {
        System.out.println("启动服务端系统……");
        try {
            // 1、创建服务端对象
            ServerSocket serverSocket = new ServerSocket(Constant.PORT);
            // 2、监听客户端连接
            while (true) {
                // 3、接收客户端对象
                System.out.println("等待客户端连接……");
                Socket socket = serverSocket.accept();
                // 4、创建线程处理
                new SeverReaderThread(socket).start();
                System.out.println("客户端" + socket.getInetAddress().getHostAddress() + "连接成功！");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
